class InitMigration < ActiveRecord::Migration
  
  def self.up
    create_table :users, :force => true do |t|
      t.integer	:t_user_id,	:null => false
      t.string	:nick,	:null => false
      t.boolean	:sex
      t.integer	:seller_credit_id
      t.string	:location
      t.string	:created
      t.string	:last_visit
      t.timestamps
    end
    
    create_table :user_credits, :force => true do |t|
      t.integer	:level
      t.integer	:score
      t.integer	:total_num
      t.integer	:good_num
      t.timestamps
    end
    
    create_table :item_categories, :force => true do |t|
      t.integer	:cid, :null => false
      t.integer	:parent_cid, :null => false, :default => 0
      t.string	:name, :null => false
      t.integer	:cat_level, :null => false, :default => 0
      t.boolean	:is_parent, :default => 0
      t.integer	:sort_order, :default => 0
      t.timestamps
    end
    
    create_table :item_properties, :force => true do |t|
      t.integer	:pid, :null => false
      t.integer	:parent_pid
      t.integer	:parent_vid
      t.string	:name, :null => false
      t.text	:property_values
      t.boolean	:status, :default => 1
      t.integer	:sort_order, :default => 0
      t.timestamps
    end
    
    create_table :property_values, :force => true do |t|
			t.integer	:cid, :null => false
			t.integer	:pid, :null => false
			t.string	:property_name
			t.integer	:vid
			t.string	:name
			t.string	:name_alias
			t.boolean	:is_parent, :default => 0
			t.boolean	:status, :default => 1
			t.integer	:sort_order, :default => 0
      t.timestamps
    end
    
    create_table :items, :force => true do |t|
			t.string	:iid, :null => false
			t.string	:detail_url, :null => false
			t.string	:num_iid, :null => false
			t.integer	:user_id, :null => false
			t.string	:nick
			t.text	:seller_cids
			t.text	:props
			t.text	:input_ids
			t.text	:input_str 
			t.text	:description
			t.string	:pic_url
			t.integer	:num
			t.integer	:valid_thru
			t.string	:location
			t.decimal	:price,	:precision => 10, :scale => 2, :default => 0.0, :null => false
			t.decimal	:post_fee, :precision => 10, :scale => 2, :default => 0.0, :null => false
			t.decimal	:express_fee, :precision => 10, :scale => 2, :default => 0.0, :null => false
			t.decimal	:ems_fee, :precision => 10, :scale => 2, :default => 0.0, :null => false
			t.boolean	:has_discount, :default => 0
			t.string	:product_id
			t.decimal	:auction_point, :precision => 10, :scale => 2, :default => 0.0
			t.string	:property_alias
			t.string	:item_images_ids
			t.string	:property_images_ids
			t.integer	:cat1_id
			t.string	:cat1_name
			t.integer	:cat2_id
			t.string	:cat2_name
			t.integer	:cat3_id
			t.string	:cat3_name
      t.timestamps
    end
    
    create_table :item_images, :force => true do |t|
    	t.string :url, :null => false
    	t.integer :position, :default => 0, :null => false
    	t.timestamps
    end
    
    create_table :property_images, :force => true do |t|
    	t.string :url, :null => false
    	t.string :properties
    	t.integer :position, :default => 0, :null => false
    	t.timestamps
    end
    
    create_table :brands, :force => true do |t|
    	t.string :vid
    	t.string :name
    	t.integer :pid
    	t.string :property_name
    	t.timestamps
    end
    
    create_table :recommend_items, :force => true do |t|
    	t.int :related_id, :null => false
    	t.integer :cat1_id
    	t.integer :position
    	t.integer :recommend_type
    	t.boolean :is_active, :default => 1
    	t.integer :flag, :default => 0
    	t.timestamps
    end
  end
  
  def self.down
    drop_table	:users
    drop_table	:user_credits
    drop_table	:item_categories
    drop_table	:item_properties    
    drop_table	:property_values
    drop_table	:items
    drop_table 	:item_image
    drop_table	:property_images
    drop_table	:brands
    drop_table	:recommend_items
  end
  
end
